package com.aabte.design2.behavioral.command;

import lombok.Data;

/**
 * 命令基类会为所有具体命令定义通用接口
 *
 * @author Daniel
 * @version 1.0
 * @date 2020/5/3
 */
@Data
public abstract class AbstractCommand {

    private Application app;
    private Editor editor;
    private String backup;

    public AbstractCommand(Application app, Editor editor) {
        this.app = app;
        this.editor = editor;
    }

    public void saveBackup() {
        backup = editor.getText();
    }

    public void undo() {
        editor.setText(backup);
    }

    /**
     * 执行方法被声明为抽象以强制所有具体命令提供自己的实现。该方法必须根
     * 据命令是否更改编辑器的状态返回 true 或 false。
     *
     * @return 是否记录命令
     */
    public abstract boolean execute();
}
